package com.example.mapper;

import com.example.pojo.GoodsCate;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsCateMapper {
    // 查找最小空缺ID
    @Select("SELECT MIN(t1.id + 1) FROM `goods-cate` t1 " +
            "LEFT JOIN `goods-cate` t2 ON t1.id + 1 = t2.id " +
            "WHERE t2.id IS NULL AND t1.id < 99")
    Integer findFirstGapId();

    // 查找当前最大ID
    @Select("SELECT COALESCE(MAX(id), 0) FROM `goods-cate`")
    Integer findMaxId();

    // 新增商品分类（添加cate_pic字段）
    @Insert("insert into `goods-cate`(id, name, description, cate_pic, create_time, update_time) " +
            "values(#{id}, #{name}, #{description}, #{catePic}, #{createTime}, #{updateTime})")
    void add(GoodsCate goodsCate);

    // 查询所有分类列表
    @Select("select * from `goods-cate`")
    List<GoodsCate> list();

    // 根据id查看分类详情
    @Select("select * from `goods-cate` where id = #{id}")
    GoodsCate findById(Integer id);

    // 更新分类（添加cate_pic字段）
    @Update("update `goods-cate` set name=#{name}, description=#{description}, " +
            "cate_pic=#{catePic}, update_time=#{updateTime} where id=#{id}")
    void update(GoodsCate goodsCate);

    // 删除分类
    @Delete("DELETE FROM `goods-cate` WHERE id = #{id}")
    void delete(Integer id);
}